<template lang="jade">
.app-container
  //- .header
    h1.page-title 活动公告
    a.backup.icon-angle-left(href='javascript:history.go(-1)')
  .weui-panel__bd
    router-link.weui-media-box.weui-media-box_text(v-for="item in list", :key="item.nid", tag="div", :to="`/news/${item.nid}`")
      h4.weui-media-box__title {{ item.title }}
      p.weui-media-box__desc {{ item.body.summary }}
      div.weui-media-box__info
        .weui-media-box__info__meta 发布时间 {{ item.created | formatTime('yy-mm-dd') }}
  .weui-loadmore(v-if="!isLast")
    template(v-if="loading")
      i.weui-loading
      span.weui-loadmore__tips 正在加载
    template(v-else)
      span.weui-loadmore__tips(@click="loadmore") 查看更多
  .weui-loadmore.weui-loadmore__line(v-if="isLast")
    span.weui-loadmore__tips 已全部加载

</template>

<script>
import API from '../api-new'
export default {
  data () {
    return {
      loading: true,
      list: []
    }
  },
  mounted () {
    let page = this.$route.query.page || 0
    this.fetchData(page)
  },
  methods: {
    loadmore () {
      if (!this.isLast) {
        let page = ++this.page
        this.loading = true
        this.fetchData(page)
      }
    },
    fetchData (page) {
      API.fetchNews(10, page).then(res => {
        this.list = this.list.concat(res.list)
        this.isLast = res.isLast
        this.page = page
        this.loading = false
      })
    }
  }
}
</script>
